public void Process(GLPBinaryPictureData picturePackage, NmeaConnection conn)
        {
            if (picturePackage == null)
            {
                throw new ArgumentNullException("Picture package is null.");
            }
            if (conn == null)
            {
                throw new ArgumentNullException("Connection is null.");
            }
            ISavePicture savePicture    = new SavePicture();
            string       strPictureName = picturePackage.RTC.ToString("s", CultureInfo.InvariantCulture);
            int          iD             = conn.Device.ID;

            if (picturePackage.PackageIndex == 1)
            {
                long?      lTrackDataID = null;
                TrackPoint trackPoint   = this.m_ResolvePosition(conn.Device.DeviceOwnerID, picturePackage.RTC);
                if (trackPoint != null)
                {
                    lTrackDataID = new long?(trackPoint.ID);
                }
                savePicture.NewPicture(picturePackage.RTC.ToString("s", CultureInfo.InvariantCulture), iD, picturePackage.RTC, lTrackDataID, (int)picturePackage.TotalPackages, 0, null);
            }
            savePicture.SavePictureData(strPictureName, iD, (int)picturePackage.PackageIndex, picturePackage.PictureData);
        }
Exemple #2
0
        /// <summary>
        /// SMS from device.
        /// </summary>
        /// <param name="msg"></param>
        public override void TranslateFromDevice(ProviderMessage msg)
        {
            NmeaConnection.Login("MSISDN", msg.ClientAddress, null);

            ProcessPendingCommand(msg);

            // No framework processing of SMS implemented yet.
        }
Exemple #3
0
        /// <summary>
        /// Data from device. TCP
        /// </summary>
        /// <param name="arrData"></param>
        /// <param name="iStart"></param>
        /// <param name="iLength"></param>
        public override void TranslateFromDevice(byte[] arrData, int iStart, int iLength)
        {
            m_nlog.Info(GLPParser.LogBinary("GLP", arrData));

            m_parser.Write(arrData);

            GLPBase report  = null;
            bool    sendAck = false;

            while ((report = m_parser.NextReport()) != null)
            {
                if (report.sendAck)
                {
                    sendAck = true;
                }

                if (!report.parseError)
                {
                    if (report.loginPacket == false)
                    {
                        // Login
                        if (NmeaConnection.Session == null)
                        {
                            try
                            {
                                NmeaConnection.Login("IMEI", report.DeviceID, null);
                            }
                            catch (Franson.Directory.AuthenticationException)
                            {
                                throw;
                            }
                        }


                        // Pending outgoing commands.
                        ProcessPendingCommand(report);

                        if (report.CameraStatus == 2)
                        {
                            report.CameraStatus = 0;
                            NmeaConnection.ProtocolToDevice("ACK1");
                        }

                        if (report.CameraStatus == 3) //pobieranie zdjec
                        {
                            report.CameraStatus = 0;
                            GLPPictureProcessor glpPictureProcessor = CameraPluginServices.TryCreatePictureProcessor();
                            if (glpPictureProcessor != null)
                            {
                                try
                                {
                                    glpPictureProcessor.Process(report as GLPBinaryPictureData, this.NmeaConnection);
                                    NmeaConnection.ProtocolToDevice("ACK1");
                                }
                                catch
                                {
                                    NmeaConnection.ProtocolToDevice("ACK2");    //przerywamy z ponowieniem
                                }
                            }
                            else
                            {
                                NmeaConnection.ProtocolToDevice("ACK3"); //mnie ma w ogole zainstalowanej kamery wiec przerywamy calkiem
                            }
                        }
                        else if (report.TerminalData != null)
                        {
                            FRCMD  fRCMD = null;
                            string text  = UTF8Encoding.UTF8.GetString(report.TerminalData);
                            if (text == "GLP_UNDELIVERED\0")
                            {
                                text = Franson.Directory.Session.CurrentSession.Locale.Lang["GLP"].Server["GLP_UNDELIVERED"];
                            }
                            if (text == "GLP_DELIVERED\0")
                            {
                                text = Franson.Directory.Session.CurrentSession.Locale.Lang["GLP"].Server["GLP_DELIVERED"];
                            }


                            if (report.JobStatus == 100)
                            {
                                fRCMD = new ChangeAssignedWorkerStateCmdBuilder(CommandDirection.DeviceToGpsGate, report.JobID, NmeaConnection.Device.DeviceOwnerID, AssignedWorkerState.Active);
                            }
                            else if (report.JobStatus == 101)
                            {
                                fRCMD = new ChangeAssignedWorkerStateCmdBuilder(CommandDirection.DeviceToGpsGate, report.JobID, NmeaConnection.Device.DeviceOwnerID, AssignedWorkerState.Completed);
                            }
                            else if (report.JobStatus == 102)
                            {
                                fRCMD = new ChangeAssignedWorkerStateCmdBuilder(CommandDirection.DeviceToGpsGate, report.JobID, NmeaConnection.Device.DeviceOwnerID, AssignedWorkerState.Assigned);
                            }
                            else if (report.JobStatus == 103)
                            {
                                fRCMD = new ChangeAssignedWorkerStateCmdBuilder(CommandDirection.DeviceToGpsGate, report.JobID, NmeaConnection.Device.DeviceOwnerID, AssignedWorkerState.Assigned);
                            }
                            else if (report.JobStatus == 104)
                            {
                                fRCMD = new DeleteAssignedWorkerCmdBuilder(CommandDirection.DeviceToGpsGate, report.JobID, NmeaConnection.Device.DeviceOwnerID);
                            }
                            else
                            {
                                fRCMD = new FRCMD(null, "_ReceiveChatText", new string[] { text });
                            }
                            //serwer odbiera ale nie wysyła
                            //GpsGateClientCmd client = new GpsGateClientCmd("localhost", 30175);
                            //client.Connect("IMEI", report.DeviceID, null);
                            //client.CmdToServer(cmd);

                            if (fRCMD != null)
                            {
                                GpsGateClientDirect client = new GpsGateClientDirect();
                                client.Connect(NmeaConnection.Device, this.NmeaConnection);
                                client.CmdToServer(fRCMD);
                                client.Disconnect();
                            }
                        }
                        else
                        {
                            // Report to GpsGate Framework.
                            ToGpsGate(report.TrackPoint, report.Status);
                        }
                    }
                    else
                    {
                        // Login
                        if (NmeaConnection.Session == null)
                        {
                            NmeaConnection.Login("imei", report.DeviceID, null);
                        }

                        // to keep connection alive
                        ToGpsGate(null, null);
                    }
                }
            }

            if (sendAck)
            {
                NmeaConnection.ProtocolToDevice("ACK1");
            }
        }
Exemple #4
0
 /// <summary>
 /// Create GLP protocol object
 /// </summary>
 /// <param name="conn"></param>
 public GLPProtocol(NmeaConnection conn)
     : base(conn)
 {
 }
Exemple #5
0
 public override void TunnelToDevice(byte[] arrData)
 {
     NmeaConnection.ProtocolToDevice(arrData);
 }