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"); } } }
private IMessage Decode2(string buffer) { if (buffer == null) { return(null); } if (ParserUtils.IsInvalidDeviceId(Id) && !buffer.StartsWith(Reporte.HandShake)) { return(FactoryQueryHandShake(this)); } IMessage salida; var data = buffer.Split(';')[0].Split(','); var pos = GetPos(data); var msgId = GetMessageId(buffer); var tipoReporte = data[0]; //var requestTimestamp = data.SingleOrDefault(s => s.StartsWith("rt")); switch (tipoReporte) { case Reporte.HandShake: salida = FactoryHandShake(this, data, msgId, pos, DataProvider); break; case Reporte.KeepAlive: salida = FactoryKeepAlive(this, data, msgId); break; case Reporte.Position: salida = FactoryPositionOrEvent(this, data, msgId); break; case Reporte.Mensaje: salida = FactoryMensaje(this, data, msgId, pos); break; default: //es un ack o un mensaje no reconocido, no se responde, solo paso la info arriba salida = new UserMessage(Id, msgId); break; } CheckFota((int)msgId); var fotaCmd = Fota.Peek(this); if (!(salida is ConfigRequest) && !string.IsNullOrEmpty(fotaCmd)) { Lastsentmessageid = (ulong)GetMsgId(fotaCmd); salida.AddStringToPostSend(fotaCmd); } return(salida); }
public override IMessage Decode(IFrame frame) { if (ParserUtils.IsInvalidDeviceId(Id)) { return(null); } var s = Encoding.ASCII.GetString(frame.Payload, 0, frame.Payload.Length).Split(','); if (!s[0].StartsWith("+")) { return(null); } if (s[0] == Report.Exception || s[0] == Report.Exception2) { //deberia detectar si es un error en el foteo y archivar lo que se quiera fotear? return(new TextEvent(Id, 0, DateTime.UtcNow) { Text = String.Format("Error en dispositivo: Tipo={0} Comando={1} Parameter={2} Extra={3}", s[1], s[2], s[3], s[4]) }); } var mid = GetMessageId(s.Last()); var tiempo = DateTimeUtils.SafeParseFormat(s[s.Length - 2], "yyyyMMddHHmmss"); String peeked; var res = Decode2(mid, s, tiempo, out peeked); if (res != null) { res.Tiempo = tiempo; if (!s[0].StartsWith("+ACK:") || s[0] == Report.Heartbeat) { res.AddStringToSend(String.Format("+SACK:{0}", s.Last())); peeked = Fota.Peek(this); } res.AddStringToPostSend(peeked); } return(res); }
// TODO: unificar GTEDeviceCommand e INodeMessage si se puede private void SendPendingFota(ref IMessage msg) { string pending = Fota.Peek(this); if (String.IsNullOrEmpty(pending)) { return; } if (CheckImageSession(pending)) { return; } //procesar primero el pendiente pending = CheckConditionsBeforeSendPending(pending); if (String.IsNullOrEmpty(pending)) { return; } #region SendPending var gteDC = BaseDeviceCommand.createFrom(pending, this, null); pending = gteDC.ToString(true); msg = (msg ?? new UserMessage(Id, 0)); msg.AddStringToPostSend(pending); if (LastSent == null || LastSent.GetText(null) != pending) { LastSent = new INodeMessage((ulong)Id, pending, DateTime.UtcNow); } #endregion SendPending }
/*protected override void OnMemberwiseClone() * { * //reconfiglimit = DateTime.MinValue; * }//*/ #endregion #region Private Members private IMessage Decode2(ulong mid, String[] s, DateTime dtsent) { var msg = Decode3(mid, s, dtsent); if (msg == null) { return(null); } var pending = Fota.Peek(this); if (!String.IsNullOrEmpty(pending)) { Lastsentmessageid = GetMessageId(pending); if (msg.IsPending()) { msg.AddStringToPostSend(pending); } else { msg.AddStringToSend(pending); } } return(msg); }
private IMessage Decode2(ulong mid, String[] s, DateTime dtsent, out String peeked) { peeked = null; var ss = s[0].Replace("+BUFF", "+RESP"); switch (ss) { case Report.Fixed: return(ParsePositions(Id, mid, s)); case Report.CrossBorderEvent: return(ParseEventWithPosition(Id, mid, s, s[5] == "1" ? MessageIdentifier.InsideGeoRefference : MessageIdentifier.OutsideGeoRefference, dtsent, 7, null)); case Report.SpeedAlarm: return(ParsePosition(Id, mid, s)); case Report.SosEvent: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.PanicButtonOn, dtsent, 7, null)); case Report.RtoRtl: return(ParsePosition(Id, mid, s)); case Report.DevicePowerUpFirstPosition: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.GpsSignalOn, dtsent, 7, null)); case Report.NonMovementEvent: { var ev = (s[5] == "0") ? MessageIdentifier.StoppedEvent : ((s[5] == "1") ? MessageIdentifier.StartMovementEvent : /*s[5] == "2"*/ MessageIdentifier.Freefall); return(ParseEventWithPosition(Id, mid, s, ev, dtsent, 7, null)); } case Report.LocationByCall: { var res = (Event)ParseEventWithPosition(Id, mid, s, MessageIdentifier.BlackcallIncoming, dtsent, 5, null); res.SensorsDataString = s[4]; return(res); } case Report.LocationAsCentreOfGeofence: return(ParsePosition(Id, mid, s)); case Report.DeviceInformation: return(new UserMessage(Id, mid)); case Report.GpsRequest: return(new UserMessage(Id, mid)); case Report.GetAllConfiguration: return(new UserMessage(Id, mid)); case Report.RealTimeOperationCid: return(new UserMessage(Id, mid)); case Report.RealTimeOperationCsq: return(new UserMessage(Id, mid)); case Report.RealTimeOperationVer: return(new UserMessage(Id, mid)); case Report.RealTimeOperationBat: return(FactoryEventWithoutPosition(Id, mid, MessageIdentifier.BateryInfo, String.Format("BatteryPercentage:{0},BatteryVoltage:{1},ExternalPowerSupply:{2},Charging:{3},LedOn:{4}", s[6], s[7], s[4], s[8], s[9]))); case Report.RealTimeOperationTmz: return(new UserMessage(Id, mid)); case Report.PowerOn: return(FactoryEventWithoutPosition(Id, mid, MessageIdentifier.DeviceTurnedOn, null)); case Report.PowerOff: return(FactoryEventWithoutPosition(Id, mid, MessageIdentifier.DeviceShutdown, null)); case Report.ConnectingExternalPowerSupply: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.PowerReconnected, dtsent, 4, null)); case Report.DisconnectingExternalPowerSupply: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.PowerDisconnected, dtsent, 4, null)); case Report.BatteryLow: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.BateryLow, dtsent, 5, String.Format("BatteryVoltage:{0}", s[4]))); case Report.StartCharging: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.BatteryChargingStart, dtsent, 4, null)); case Report.StopCharging: return(ParseEventWithPosition(Id, mid, s, MessageIdentifier.BatteryChargingStop, dtsent, 5, null)); case Report.DeviceMotionStateIndication: return(new UserMessage(Id, mid)); case Report.GpsAntennaStatusIndication: return(new UserMessage(Id, mid)); case Report.SwitchOnOffGeofence0ViaFunctionKey: return(new UserMessage(Id, mid)); case Report.Heartbeat: return(ParseHeartbeat(Id, mid, s)); default: if (s[0].StartsWith("+ACK:")) { var midR = Convert.ToUInt64(s[s.Length - 3], 16); peeked = Fota.Peek(this); var midF = Convert.ToUInt64(peeked.Split(',').Last().TrimEnd('$'), 16); if (midR == midF) { Fota.Dequeue(this, null); } } return(null); } }