public override INode Factory(IFrame frame, int formerId) { string buffer = AsString(frame); if (String.IsNullOrEmpty(buffer)) { return(null); } CusatUniversalParser parser = new CusatUniversalParser(buffer); return(DataProvider.FindByIMEI(parser.Matricula.Trim(), this)); }
public override IMessage Decode(IFrame frame) { IMessage salida = null; string buffer = AsString(frame); if (buffer == null) { return(null); } CusatUniversalParser parser = new CusatUniversalParser(buffer); /* * * * >RU1PBN177 110316154602-3292596-06883632 325 500 000 10 80 04 012|#1BDE4B< * patente 8 caracteres DDMMYYHHMMSS 8dig lat 8dig long fix3d age 3 vel Sat dop enhex 2 evento 3 * >RU1 PBN177 ------------ 110316154602 -3292596 -0688363 2 325 500 80 04 012 * * * * * Universal 6, este es nuestro y hay algunas variantes mas ( ancho fijo ): * RU1XYZ12345DDMMYYHHMMSS-3400000-58000003000000000080280017|#1234 * RU1 = OPCODE * XYZ12345 = MATRICULA ( 8) * DDMMYYHHMMSS = FECHA * -3400000 = LAT * -5800000 = LON * 3 = Fix 3D * 000 = Age * 000 = Vel * 000 = Dir * 08 = Sat * 02 = Dop * 80 = ent en hexa ( 128 ) * 017 = evento * 1234 = número de bloque * NOTA: entre “|” y “#” está pensado para poner data ( quizás variable ) en el futuro, nunca se usó. * * * * * */ ulong msgId = NextSequence;// ulong.Parse(parser[6]); GPSPoint pos; var code = EventCodes.Position; var time = DateTime.ParseExact(parser.Fecha, "ddMMyyHHmmss", System.Globalization.CultureInfo.InvariantCulture); var lat = float.Parse(parser.Latitud.Insert(3, ","));// parser[2].Replace('.', ',')); var lon = float.Parse(parser.Longitud.Insert(4, ",")); var vel = float.Parse(parser.Vel); var dir = float.Parse(parser.Dir); short codeevent = (short)0; /* * 0=PEDIDO DE POSICION * 1=BOTON DE PANICO * 8=CONTACTO ON * 15=BAT. DESCONECTADA * 16=CONTACTO OFF * 17=POSICION EN CONTACTO * 18=POSICION SIN CONTACTO * 23=RESET DE EQUIPO * * 0=PEDIDO DE POSICION * 8001=BOTON DE PANICO * 8008=CONTACTO ON * 8015=BAT. DESCONECTADA * 8016=CONTACTO OFF * 8017=POSICION EN CONTACTO * 8018=POSICION SIN CONTACTO * 8023=RESET DE EQUIPO * * * */ switch (parser.Evento) { case "001": { codeevent = 8001; //8001=BOTON DE PANICO } break; case "008": { codeevent = 8008; //8008=CONTACTO ON } break; case "015": { codeevent = 8015; //8015=BAT. DESCONECTADA } break; case "016": { codeevent = 8016; //8016=CONTACTO OFF } break; case "017": { codeevent = 8017; //8017=POSICION EN CONTACTO } break; case "018": { codeevent = 8018; //8018=POSICION SIN CONTACTO } break; case "023": { codeevent = 8023; //8023=RESET DE EQUIPO } break; default: break; } var hdop = 0; pos = GPSPoint.Factory(time, lat, lon, vel, dir, 0, hdop); var device = DataProvider.FindByIMEI(parser.Matricula, this); var deviceid = 0; if (device == null) { var empresa = _daoFactory.EmpresaDAO.FindByCodigo("QP"); var tipodispositivo = _daoFactory.TipoDispositivoDAO.FindByModelo("CUSATUNIVERSAL6"); Dispositivo newdispo = new Dispositivo(); newdispo.Empresa = empresa; // newdispo.Linea = _daoFactory.LineaDAO.FindByNombre(empresa.Id, "Generica"); newdispo.TipoDispositivo = tipodispositivo; newdispo.Clave = parser.Matricula.ToString(); newdispo.Tablas = ""; newdispo.Port = 6070; // newdispo.Firmware = _daoFactory.FirmwareDAO.FindById(5); newdispo.Imei = parser.Matricula.ToString(); newdispo.Codigo = parser.Matricula.ToString(); _daoFactory.DispositivoDAO.Save(newdispo); if (_daoFactory.CocheDAO.FindByPatente(empresa.Id, parser.Matricula.ToString()) == null) { Coche newcoche = new Coche(); newcoche.Patente = parser.Matricula.ToString(); newcoche.Interno = parser.Matricula.ToString(); newcoche.ModeloDescripcion = ""; newcoche.Empresa = empresa; newcoche.Dispositivo = newdispo; _daoFactory.CocheDAO.Save(newcoche); } else { Coche coche = _daoFactory.CocheDAO.FindByPatente(empresa.Id, parser.Matricula.ToString()); coche.Dispositivo = newdispo; _daoFactory.CocheDAO.Save(coche); } deviceid = newdispo.Id; } else { deviceid = DataProvider.FindByIMEI(parser.Matricula.ToString(), this).Id; } if (codeevent == 0) { salida = pos.ToPosition(deviceid, msgId); } else { salida = new Event(codeevent, -1, deviceid, msgId, pos, pos.GetDate(), "", new List <long>(), true); } return(salida); /* * * * * if (ParserUtils.IsInvalidDeviceId(Id)) return null; * * var buffer = AsString(frame); * if (buffer == null || !buffer.Contains(">RU")) return null; * * var dt = DateTimeUtils.SafeParseFormat(buffer.Substring(28, 12), "ddMMyyHHmmss"); * var codEv = GetEventCode(buffer); * * //var msgId = GetMsgId(buffer); //siempre es 0001!!! * var msgId = (ulong)((dt.Ticks << 8) + codEv); * * * var gpsPoint = ParseRu2(buffer, dt); * return GetSalida(gpsPoint, dt, "00000000", codEv, this, msgId);*/ }