Exemplo n.º 1
0
 public CalampParser(Byte[] ClientData, string ExceptionLogPth, string FilePth, bool WriteLgFile, bool WriteExcetionLg, string SignalRAPi, ref List <UdpClientInfo> UDPClntList, ref UdpClientInfo UDPClnt, List <string> LstALLIMEI, string ConnectionStr)
 {
     ClntData            = ClientData;
     ExceptionLogPath    = ExceptionLogPth;
     LogFilePath         = FilePth;
     SgnalRApi           = SignalRAPi;
     WriteLogFileflg     = WriteLgFile;
     WriteExceptionLgflg = WriteExcetionLg;
     ObjComnOp           = new TcpService.CommonOperation(LogFilePath, ExceptionLogPath, SgnalRApi);
     objUDPClnt          = UDPClnt;
     lstUDPClnt          = UDPClntList;
     ObjVehicleObj       = new FM_VehicleBL(ConnectionStr);
     AllIMEILst          = LstALLIMEI;
 }
Exemplo n.º 2
0
        public Byte[] ParseEventRpt()
        {
            try
            {
                string   TrackerHexaResponse = "";
                string   dataFromClient      = "";
                string[] HexCollection;
                string   UDPData = "";

                TrackerHexaResponse = BitConverter.ToString(ClntData, 0, ClntData.Length).Replace("-", " ");
                HexCollection       = TrackerHexaResponse.Split(' ');
                ClntDevIDLth        = GetDeviceIDLength(HexCollection);

                int    CounterDiff = StdDevIDLth - ClntDevIDLth;
                int    MessageIdentifierLocation = 10 - CounterDiff;
                string CurrentPktIMEI            = GetDeviceID(HexCollection);

                if (!(lstUDPClnt.Exists(x => x.TrackerID == CurrentPktIMEI)))
                {
                    bool ClientIMEI = AllIMEILst.Contains(CurrentPktIMEI);
                    //bool ClientIMEI = ObjVehicleObj.ValidateVehicleIMEI("Validate_IMEI", objUDPClnt.TrackerID);

                    if (!ClientIMEI)
                    {
                        return(null);
                    }
                }

                if (HexCollection[MessageIdentifierLocation] == "2")
                {
                    dataFromClient = System.Text.Encoding.ASCII.GetString(ClntData);
                    DataPacket DataPktobj = new DataPacket();

                    DataPktobj.UTCTimeAndDate  = ParseUpdateTime(HexCollection);
                    DataPktobj.UTCTimeAndDate  = ParseTimeOfFix(HexCollection);
                    DataPktobj.Latitude        = Parselat(HexCollection);
                    DataPktobj.Longitude       = ParseLong(HexCollection);
                    DataPktobj.Altitude        = ParseAltitude(HexCollection);
                    DataPktobj.Speed           = ParseSpeed(HexCollection);
                    DataPktobj.Direction       = ParseHeadingDirection(HexCollection);
                    DataPktobj.Rotation        = DegreesToCardinal(DataPktobj.Direction);
                    DataPktobj.TrackerID       = GetDeviceID(HexCollection);
                    DataPktobj.GPSSignalStatus = "Valid";
                    DataPktobj.IsOfflineData   = false;

                    objUDPClnt.TrackerID = DataPktobj.TrackerID;

                    if (lstUDPClnt.Exists(x => x.TrackerID == objUDPClnt.TrackerID))
                    {
                        UdpClientInfo UDPClnt = lstUDPClnt.FirstOrDefault(x => x.TrackerID == objUDPClnt.TrackerID);
                        if (UDPClnt != null)
                        {
                            UDPClnt.IPAddress      = objUDPClnt.IPAddress;
                            UDPClnt.LstPktRcvdTime = DateTime.Now;
                        }
                    }
                    else
                    {
                        lstUDPClnt.Add(objUDPClnt);
                    }

                    string data = "";

                    if (WriteLogFileflg)
                    {
                        data = Environment.NewLine + DateTime.Now.ToString() + " UDP Gps Data Parsed ";
                        data = data + Environment.NewLine + "DeviceID : " + DataPktobj.TrackerID;
                        data = data + Environment.NewLine + "Date Time: " + ": " + DataPktobj.UTCTimeAndDate.ToString();
                        data = data + Environment.NewLine + "Latitude: " + ": " + DataPktobj.Latitude.ToString();
                        data = data + Environment.NewLine + "Longitutude: " + ": " + DataPktobj.Longitude.ToString();
                        data = data + Environment.NewLine + "Speed: " + ": " + DataPktobj.Speed.ToString();
                        data = data + Environment.NewLine + "Degree: " + ": " + DataPktobj.Direction.ToString();
                        data = data + Environment.NewLine + "Direction: " + ": " + DataPktobj.Rotation.ToString();
                        data = data + Environment.NewLine;
                        ObjComnOp.WriteFile(data);
                    }

                    InputOutputStatus objStatus = new InputOutputStatus();
                    objStatus.InEngineOnOff    = true;
                    DataPktobj.ObjInpOutStatus = objStatus;

                    ObjComnOp.SendDataToApi(DataPktobj);

                    if (HexCollection[9] == "01")
                    {
                        return(SentAck());
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(null);
            }

            catch (Exception ex)
            {
                if (WriteExceptionLgflg)
                {
                    string exception = Environment.NewLine + DateTime.Now.ToString() + " ParseEventRpt : " + ex.ToString();
                    ObjComnOp.WriteExceptionFile(exception);
                }
                return(null);
            }
        }
Exemplo n.º 3
0
 public CalampParser(UdpClientInfo objUDPClnt, string ConnectionStr)
 {
     this.objUDPClnt = objUDPClnt;
     ObjVehicleObj   = new FM_VehicleBL(ConnectionStr);
 }