public bool UnloadRoute(ulong messageId, Destination[] route, int routeId) { string cmd = null; var md = GetMessagingDevice(); switch (md) { case MessagingDevice.Garmin: var config = new StringBuilder(); config.AppendFormat("{0}{1}", BaseDeviceCommand.createFrom(">SSG160<", this, null).ToString(false), Environment.NewLine); config.Append(GarminFmi.EncodeDataDeletionFor(DataDeletionProtocolId.DeleteAllStopsOnTheClient).ToTraxFM(this, false)); foreach (var p in route) { config.Append(GarminFmi.EncodeDeleteTextmessage((UInt32)p.Code).ToTraxFM(this, false)); } config.Append(Environment.NewLine); config.Append(Fota.VirtualMessageFactory(MessageIdentifier.UnloadRouteSuccess, 0)); cmd = config.ToString(); break; case MessagingDevice.Mpx01: break; } SendMessages(cmd, messageId, md); return(true); }
public bool ReloadRoute(ulong messageId, Destination[] route, bool sort, int routeId) { string cmd = null; var md = GetMessagingDevice(); switch (md) { case MessagingDevice.Garmin: var config = new StringBuilder(); config.AppendFormat("{0}{1}", BaseDeviceCommand.createFrom(">SSG161<", this, null).ToString(false), Environment.NewLine); //config.Append(GarminFmi.EncodeDataDeletionFor(DataDeletionProtocolId.DeleteAllStopsOnTheClient).ToTraxFM(this, false)); foreach (var p in route) { var stopStr = GarminFmi.EncodeA603StopProtocol(p.Point, p.Code, p.Text).ToTraxFM(this, false); //STrace.Debug(typeof(GarminFmi).FullName, Id, "ReloadRoute: Stop ID=" + Convert.ToString(p.Code) + " - " + stopStr); config.Append(stopStr); } config.Append(Environment.NewLine); config.Append(Fota.VirtualMessageFactory(MessageIdentifier.ReloadRouteSuccess, NextSequence)); cmd = config.ToString(); break; case MessagingDevice.Mpx01: break; } SendMessages(cmd, messageId, md); return(true); }
private String GetFirm() { string[] fw = Encoding.ASCII.GetString(DataProvider.GetFirmware(Id)).Split(new[] { "\r\n", "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < fw.Length; i++) { fw[i] = String.Format(">SFUS{0:X4}{1}<", i, fw[i]); } return(String.Join(Environment.NewLine, fw) + fw[0].Replace(">SFUS0000", ">SFUSFFFF") + Environment.NewLine + ">SSR55AA<" + Environment.NewLine + Fota.VirtualMessageFactory(MessageIdentifier.FotaSuccess, NextSequence)); }
private String GetConfig(out String hash) { var config = new StringBuilder(DataProvider.GetConfiguration(Id).Replace("\r", "\n").Replace("\n", Environment.NewLine)); string md = DataProvider.GetDetalleDispositivo(Id, "GTE_MESSAGING_DEVICE").As(String.Empty); if (String.IsNullOrEmpty(config.ToString()) && (md != MessagingDevice.Garmin)) { hash = null; return(null); } //reemplazar cada "$ParameterName" con "ParameterValue" List <DetalleDispositivo> configParametersTable = DataProvider.GetDetallesDispositivo(Id); if (configParametersTable != null) { IEnumerable <DetalleDispositivo> configParameters = configParametersTable.Where(detalle => detalle.TipoParametro.Nombre.StartsWith("GTE_PARAM_")); foreach (DetalleDispositivo s in configParameters) { config.Replace("$" + s.TipoParametro.Nombre, s.As("--- PARAMETRO SIN VALOR! ---")); } config.Replace("$known_qtree_revision", DataProvider.GetDetalleDispositivo(Id, "known_qtree_revision").As("0")); } GetMessages(ref config); if (!String.IsNullOrEmpty(config.ToString().Trim())) { config.AppendFormat("{0}{0}Configuracion Generada Exitosamente{0}", Environment.NewLine); config.Insert(0, Fota.VirtualMessageFactory(MessageIdentifier.ConfigStart, 0)); } else { config.AppendLine("Configuracion vacia."); } config.Append(Fota.VirtualMessageFactory(MessageIdentifier.ConfigSuccess, 0)); string conf = config.ToString(); hash = conf.GetHashCode().ToString(CultureInfo.InvariantCulture); conf = conf.Replace("$revision", hash); return(conf); }
public bool SubmitTextMessage(ulong messageId, uint textMessageId, String textMessage, uint[] replies, int ackEvent) { STrace.Debug(typeof(Parser).FullName, Id, "SubmitTextMessage: messageId=" + messageId.ToString() + ",textMessageId=" + textMessageId.ToString() + ",textMessage=" + textMessage + ",replies=" + (replies == null?"null":String.Join(",", replies.Select(b => b.ToString()).ToArray()))); var md = GetMessagingDevice(); switch (md) { case MessagingDevice.Garmin: { var cnf = new StringBuilder(); // cnf.Append(GarminFmi.EncodeDeleteTextmessage(textMessageId).ToTraxFM(this, false)); if (replies != null && replies.Length > 0) { cnf.Append(GarminFmi.EncodeCannedResponseList(textMessageId, replies).ToTraxFM(this, false)); } else { cnf.Append(GarminFmi.EncodeDeleteTextmessage(textMessageId).ToTraxFM(this, false)); } cnf.Append(GarminFmi.EncodeOpenTextMessage(textMessageId, textMessage, true).ToTraxFM(this, false)); if (ackEvent != -1) { cnf.Append(Fota.VirtualMessageFactory((MessageIdentifier)ackEvent, NextSequence)); } var cmd = cnf.ToString(); SendMessages(cmd, messageId, md); break; } case MessagingDevice.Mpx01: { var cmd = EncodeMpx01Msg(textMessage, messageId, this); SendMessages(cmd, messageId, md); break; } case MessagingDevice.Sms: { var cmd = EncodeSmsMsg(textMessage, messageId, this); SendMessages(cmd, messageId, md); break; } } return(true); }
public bool SubmitLongTextMessage(ulong messageId, uint textMessageId, String textMessage, int ackEvent) { STrace.Debug(typeof(Parser).FullName, Id, "SubmitLongTextMessage: messageId=" + messageId.ToString() + ",textMessageId=" + textMessageId.ToString() + ",textMessage=" + textMessage); var md = GetMessagingDevice(); switch (md) { case MessagingDevice.Garmin: { var cnf = new StringBuilder(); cnf.Append(GarminFmi.EncodeDeleteTextmessage(textMessageId).ToTraxFM(this, false)); cnf.Append(GarminFmi.EncodeOpenLongTextMessage(textMessageId, textMessage, true).ToTraxFM(this, false)); if (ackEvent != -1) { cnf.Append(Fota.VirtualMessageFactory((MessageIdentifier)ackEvent, NextSequence)); } var cmd = cnf.ToString(); SendMessages(cmd, messageId, md); break; } case MessagingDevice.Mpx01: { var cmd = EncodeMpx01Msg(textMessage, messageId, this); SendMessages(cmd, messageId, md); break; } case MessagingDevice.Sms: { var cmd = EncodeSmsMsg(textMessage, messageId, this); SendMessages(cmd, messageId, md); break; } } return(true); }
private String GetConfig(out String hash) { var config = new StringBuilder(DataProvider.GetConfiguration(Id).Replace("\r", "\n").Replace("\n", Environment.NewLine)); if (String.IsNullOrEmpty(config.ToString())) { hash = null; return(null); } //reemplazar cada "$ParameterName" con "ParameterValue" var configParametersTable = DataProvider.GetDetallesDispositivo(Id); if (configParametersTable != null) { var configParameters = configParametersTable.Where(detalle => detalle.TipoParametro.Nombre.StartsWith("CONFIG_PARAM_")); foreach (var s in configParameters) { config.Replace("$" + s.TipoParametro.Nombre, s.As("--- PARAMETRO SIN VALOR! ---")); } } if (!String.IsNullOrEmpty(config.ToString())) { config.AppendFormat("{0}{0}Configuracion Generada Exitosamente{0}", Environment.NewLine); config.Insert(0, Fota.VirtualMessageFactory(MessageIdentifier.ConfigStart, 0)); } else { config.AppendLine("Configuracion vacia."); } config.Append(Fota.VirtualMessageFactory(MessageIdentifier.ConfigSuccess, 0)); var conf = config.ToString(); hash = conf.GetHashCode().ToString(CultureInfo.InvariantCulture); return(conf.Replace("$revision", hash)); }
private void GetMessages(ref StringBuilder config, bool deleteMessagesPreviously) { string md = DataProvider.GetDetalleDispositivo(Id, "GTE_MESSAGING_DEVICE").As(String.Empty); if (md == MessagingDevice.Garmin || md == MessagingDevice.Mpx01) { // cargar todos los posibles responses switch (md) { case MessagingDevice.Garmin: List <Logictracker.Types.BusinessObjects.Messages.Mensaje> resp = DataProvider.GetResponsesMessagesTable(Id, 0); if (deleteMessagesPreviously) { config.Append(GarminFmi.EncodeDataDeletionFor(DataDeletionProtocolId.DeleteAllCannedRepliesOnTheClient).ToTraxFM(this, false)); } if (resp != null && resp.Any()) { var respArr = resp.OrderBy(m => m.Codigo).ToArray(); config.Append(GetCannedResponses4Garmin(respArr)); } break; default: break; } config.Append(Environment.NewLine); //cargar todos los canned messages List <Logictracker.Types.BusinessObjects.Messages.Mensaje> cmt = DataProvider.GetCannedMessagesTable(Id, 0); { if ((cmt != null) && (cmt.Any())) { Logictracker.Types.BusinessObjects.Messages.Mensaje[] messagesParameters = cmt.Where(m => !m.TipoMensaje.DeEstadoLogistico).OrderBy(m => m.Codigo).ToArray(); switch (md) { case MessagingDevice.Garmin: if (deleteMessagesPreviously) { config.Append(GarminFmi.EncodeDataDeletionFor(DataDeletionProtocolId.DeleteAllCannedMessagesOnTheClient).ToTraxFM(this, false)); } config.Append(GetCannedMessages4Garmin(messagesParameters)); break; case MessagingDevice.Mpx01: int count = 0; foreach (Logictracker.Types.BusinessObjects.Messages.Mensaje m in messagesParameters.Take(10)) { count++; string texto = m.Texto.ToUpper().PadRight(32); config.Replace(String.Format("$MENSAJE{0:D2}PARTE01", count), texto.Substring(0, 16)); config.Replace(String.Format("$MENSAJE{0:D2}PARTE02", count), texto.Substring(16, 16)); config.Replace(String.Format("$MENSAJE{0:D2}CODIGO", count), m.Codigo); } for (int i = count; i < 11; i++) { const String texto = " "; config.Replace(String.Format("$MENSAJE0{0:D1}PARTE01", i), texto); config.Replace(String.Format("$MENSAJE0{0:D1}PARTE02", i), texto); config.Replace(String.Format("$MENSAJE{0:D2}CODIGO", count), "00"); } break; } } } } if (!String.IsNullOrEmpty(config.ToString().Trim())) { config.AppendFormat("{0}{0}Envio de Mensajes Generado Exitosamente{0}", Environment.NewLine); config.Insert(0, Fota.VirtualMessageFactory(MessageIdentifier.MessagesStart, 0)); config.Append(Fota.VirtualMessageFactory(MessageIdentifier.MessagesSuccess, 0)); } else { config.AppendLine("No hay mensajes para Enviar"); } }
private static void CreateGeogrillaTxtInternal(TaskData td) { try { if (td.Device.LastGeogrillaSentTimestamp.AddMinutes(30) > DateTime.UtcNow) { STrace.Log(typeof(Mensaje).FullName, null, td.Device.Id, td.Full ? LogTypes.Error : LogTypes.Debug, null, String.Format("No Foteo Geogrilla {0} por tiempo de espera minimo entre actualizaciones no alcanzado, ultima actualizacion: {1}", td.Full ? "full" : "incremental", td.Device.LastGeogrillaSentTimestamp.ToLocalTime())); return; } td.Device.LastGeogrillaSentTimestamp = DateTime.UtcNow; var gg = new GeoGrillas { Repository = new Repository { BaseFolderPath = td.Path, } }; var headers = gg.GridStructure; //si no esta bien cargado el header fix it if (headers.ActiveKey != 0x55AA55AA) { headers.ActiveKey = 0x55AA55AA; headers.DataStart = 1; } //si hay en fota un envio de qtree usar esa revision como base var fotaRev = GetPendingFotaRevision(td.Device); if (fotaRev > td.BaseRev) { td.BaseRev = fotaRev; } int revision; var changedSectorsList = new TransactionLog(gg.Repository, td.Device.Id) .GetChangedSectorsAndRevision(td.BaseRev, out revision) .SelectMany(file => file.Value, (file, sectorindex) => (file.Key) + sectorindex) .ToArray(); if (td.Full) { var countSectors = (int)(Math.Ceiling(headers.Lat_GridCount / 32.0) * Math.Ceiling(headers.Lon_GridCount / 32.0)); changedSectorsList = Enumerable.Range(0, countSectors).ToArray(); } if (changedSectorsList.Length == 0) { STrace.Debug(typeof(Parser).FullName, td.Device.Id, String.Format("Cancelando envio de geogrilla por no haber sectores cambiados, BaseRev={0} LatestRev={1}", td.BaseRev, revision)); return; } var limit = td.Device.DataProvider.GetDetalleDispositivo(td.Device.Id, "LimiteGeogrillaIncremental").As(20480); if (!td.Full && changedSectorsList.Length > limit) { //limite en el tamaño del diferencial generado de x sectores o megas, configurable en la plataforma con el detalle de dispositivo "LimiteGeogrillaIncremental". STrace.Trace(typeof(Parser).FullName, td.Device.Id, String.Format(@"Cancelando envio de geogrilla incremental por superar el limite de sectores (detalle de dispositivo ""LimiteGeogrillaIncremental""): limite={0} cantidad={1}", limit, changedSectorsList.Length)); return; } //seteo desde ya la revision en la base por si vuelven a enviar un qtree diferencial que se sume solo lo nuevo td.Device.DataProvider.SetDetalleDispositivo(td.Device.Id, "known_qtree_revision", revision.ToString("D4"), "int"); STrace.Debug(typeof(Parser).FullName, td.Device.Id, String.Format("Generando Geogrilla, BaseRev={0} LatestRev={1} GGName={2}", td.BaseRev, revision, td.Path)); if (td.Full) { var head = td.Device.DataProvider.GetDetalleDispositivo(td.Device.Id, "FullQtreePartitionsSd").AsBoolean(false) ? String.Format( ">SUV29*<{0}>SUVU55AA<{0}>SSDF,|G1,{1},TestMap<{0}>SUV29AQSDF,14,3,|G1<{0}", Environment.NewLine, td.Device.DataProvider.GetDetalleDispositivo(td.Device.Id, "QtreeSdPartitionSize").As("3800000")) : String.Empty; Fota.EnqueueLowPriority1(td.Device, 0, SetGGParams(headers, head)); } Fota.EnqueueLowPriority1(td.Device, 0, Fota.VirtualMessageFactory(MessageIdentifier.QtreeStart, td.Device.NextSequence)); ProccessSectors(td, changedSectorsList, gg, td.Device); var bytes = BitConverter.GetBytes(revision); var hexa = StringUtils.ByteArrayToHexString(bytes, 0, bytes.Length); var salida = String.Format("{1}>SSDG1,W0000008004{0}<{2}{1}>QSDG1,R0000008004<{1}", hexa, Environment.NewLine, Fota.VirtualMessageFactory(MessageIdentifier.QtreeSuccess, 0)); Fota.EnqueueLowPriority2(td.Device, td.MessageId, salida); STrace.Trace(typeof(Parser).FullName, td.Device.Id, String.Format("geogrilla a revision: {0} desde: {1} cantidad de sectores: {2}", revision, td.BaseRev, changedSectorsList.Length)); } catch (Exception e) { STrace.Exception(typeof(Parser).FullName, e, td.Device.Id, "Exception during CreateGeogrillaTxt"); } }