Пример #1
0
        /// <summary>
        /// 获取有为调度信息,并解析调度信息命令,并发送命令,发送后修改调度信息
        /// </summary>
        /// <returns></returns>
        /// <param name="dispatchControl">调度命令应用层下发命令</param>
        public void HandleDispatchControlInfo(DispatchControl dispatchControl)
        {
            //发送缓冲区
            byte[] sendBuffer = null;

            YWDispatchControlEntity entity = new YWDispatchControlEntity();
            entity.DispatchType = dispatchControl.Data.DispatchType;
            entity.SendContent = dispatchControl.SendContent;

            string gpsCode = dispatchControl.GPSCode;

            try
            {
               Logger.Trace("下发指令到GPSCode:" + gpsCode);
                //取得已建立的套接字
                Socket socket = TCPConnList.Instance().GetTCPConnection(gpsCode);
                if (socket == null)
                {
                    Logger.Trace("下发指令到GPSCode:" + gpsCode + "失败,原因是socket=null");
                    return;
                }
                //已断开连接,将其从连接列表移除
                if (socket.Connected == false)
                {
                    Logger.Trace("下发指令到GPSCode:" + gpsCode + "失败,原因是socket.connected==null");
                    //TCPConnList.Instance().RemoveTCPConnection(gpsCode);
                    return;
                }

                //解析页面下发命令
                sendBuffer = GpsDataParser.ParseControlInstruction(ControlCmdType.DispatchControl, entity);

                if (sendBuffer == null || sendBuffer.Length <= 0)
                {
                    return;
                }

                try
                {
                    //向GPS发送控制命令
                    int send = socket.Send(sendBuffer);

                    if (send > 0)
                    {
                        //向应用层确认发送成功
                        //SendAnswerToWeb(dispatchControl.SerialNumber,false, gpsCode, ControlCmdType.DispatchControl, true);
                        OnSendAnswerToWebEvent(dispatchControl.SerialNumber, false, gpsCode, ControlCmdType.DispatchControl, true);
                        Logger.Trace("GPSYouWei--Gps:" + gpsCode + " 发送调度命令成功", null);
                    }
                    else
                    {
                        //向应用层确认发送失败
                        //SendAnswerToWeb(dispatchControl.SerialNumber,false, gpsCode, ControlCmdType.DispatchControl, true);
                        OnSendAnswerToWebEvent(dispatchControl.SerialNumber, false, gpsCode, ControlCmdType.DispatchControl, true);
                        Logger.Trace("GPSYouWei--Gps:" + gpsCode + " 发送调度命令失败", null);
                    }
                }
                catch (SocketException ex)
                {
                    //向应用层确认发送失败
                    //SendAnswerToWeb(dispatchControl.SerialNumber,false, gpsCode, ControlCmdType.DispatchControl, true);
                    OnSendAnswerToWebEvent(dispatchControl.SerialNumber, false, gpsCode, ControlCmdType.DispatchControl, true);
                    Logger.Error("GPSYouWei--Gps:" + gpsCode + " 发送调度命令时异常--" + ex.Message, null);

                    //从列表移除此连接
                    //TCPConnList.Instance().RemoveTCPConnection(gpsCode);

                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
            finally
            {
                sendBuffer = null;
            }
        }
Пример #2
0
        /// <summary>
        /// 终端下发文本
        /// </summary>
        ///<param name="entity">调度实体</param>
        ///<param name="dataLen">下发文本的字节数,暂时不考虑使用双字节编码</param>
        ///<param name="sendData">解析后的字节数组</param>
        public void SendDeviceTextMsg(YWDispatchControlEntity entity, ref uint dataLen, ref byte[] sendData)
        {
            DateTime dt = DateTime.Now;

            //string sDateTime = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();

            //StringBuilder dtBuilder = new StringBuilder(sDateTime);

            byte[] bytTime = SetTimeToBCD(dt);           

            StringBuilder txtBuilder = new StringBuilder(entity.SendContent);

            int textLenth = Encoding.Default.GetBytes(entity.SendContent).Length;

            //中心下发文本解析
            YouWeiGPSInterface.EncodeSendDeviceTextMsg(
                (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                YouWeiPublicDefine.PROTOCOLVER,
                YouWeiPublicDefine.SEQUENCEID,
                0,
                0,
                (byte)entity.DispatchType,
                0,
                0,
                0,
                0,
                0,
                bytTime,
                0,
                (byte)textLenth,
                0,
                txtBuilder,
                ref dataLen,
                sendData);
        }