Beispiel #1
0
        private void save(string sender, string text, string date)
        {
            DateTime dt = DateTime.Parse(date);//DateTime.ParseExact(date, "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None);

            byte[] b       = Convert.FromBase64String(text);
            string content = Utility.GetHex(b);
            //try
            {
                TX300 x300 = new TX300(content);
                x300.package_to_msg();
                x300.TerminalID = sender + "000";
                //save(x300);
                if (x300.CommandID == 0xBB0F)
                {
                    handleBB0F(sender, x300.TerminalType);
                }

                var SMSInstance = new SmsBLL();
                var sms         = SMSInstance.GetObject();
                sms.SendTime = dt;
                sms.Sender   = sender;
                sms.Data     = text;
                // 这里接收到的都是终端汇报回来的信息
                sms.Type = Common.SMSUtility.SMS_TERMINAL;
                SMSInstance.Add(sms);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 处理卫星服务器发过来的通讯信息数据。type=data,cmd=destination,data=数据内容
        /// </summary>
        /// <returns></returns>
        private string HandleDataRequest()
        {
            var   ret  = "";
            TX300 x300 = new TX300();

            x300.Content = CustomConvert.GetBytes(data);
            x300.package_to_msg();
            HandleDataStatus(x300);
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// 处理接收到的数据
        /// </summary>
        /// <param name="data"></param>
        private void HandleReceivedData(AsyncUserDataBuffer data)
        {
            int index = 0, len = data.Buffer.Length;

            while (index < len)
            {
                byte[] temp = new byte[len - index];
                Buffer.BlockCopy(data.Buffer, index, temp, 0, len - index);
                TX300 x300 = new TX300();
                x300.Content = temp;
                x300.package_to_msg();
                // 保存历史记录
                //SaveTX300History(x300, data.ReceiveTime);
                // 更新设备状态
                HandleTX300Status(x300, data);
                if (null != _server)
                {
                    if (x300.CommandID == 0xCC00)
                    {
                        byte[] cc00 = new byte[23];
                        Buffer.BlockCopy(x300.Content, 0, cc00, 0, 17);
                        cc00[0]  = 0x17;
                        cc00[7]  = 0xFF;
                        cc00[8]  = 0xFF;
                        cc00[17] = 0x07;
                        WbsDateTime dt = new WbsDateTime(DateTime.Now);
                        Buffer.BlockCopy(dt.DateTimeToByte, 0, cc00, 19, 4);
                        dt = null;
                        if (data.PackageType == AsyncDataPackageType.TCP)
                        {
                            _server.Send(data.SocketHandle, cc00);
                        }
                        else
                        {
                            _server.Send(data.Port, data.IP, cc00);
                        }
                        cc00 = null;
                    }
                    else
                    {
                        // 返回回执
                        TX300Resp resp = new TX300Resp();
                        resp.CommandID  = x300.CommandID;
                        resp.PackageID  = x300.PackageID;
                        resp.SequenceID = x300.SequenceID;
                        resp.Status     = 0;
                        resp.Package();
                        if (data.PackageType == AsyncDataPackageType.TCP)
                        {
                            _server.Send(data.SocketHandle, resp.Content);
                        }
                        else
                        {
                            _server.Send(data.Port, data.IP, resp.Content);
                        }
                    }
                }
                HandleCommandResponsed(x300);
                index += x300.TotalLength;
            }
        }
Beispiel #4
0
        /// <summary>
        /// 处理接收到的数据
        /// </summary>
        /// <param name="data"></param>
        private void HandleReceivedData(AsyncUserDataBuffer data)
        {
            int index = 0, len = data.Buffer.Length;

            while (index < len)
            {
                byte[] temp = new byte[len - index];
                Buffer.BlockCopy(data.Buffer, index, temp, 0, len - index);
                TX300 x300 = new TX300();
                x300.Content = temp;
                temp         = null;
                x300.package_to_msg();
                // 保存历史记录
                //SaveTX300History(x300, data.ReceiveTime);
                // 更新设备状态
                HandleTX300Status(x300, data);
                // 处理命令回复
                if (x300.CommandID != 0xBB0F)
                {
                    // 不要处理0xBB0F的命令返回数据
                    HandleGsmCommandResponsed(x300);
                }
                // 是否需要返回包
                bool isNeedResponse = false;
                // SMS消息不需要返回包
                if (x300.ProtocolType > Protocol.ProtocolTypes.SMS)
                {
                    if (x300.CommandID == 0xCC00 || x300.CommandID == 0xBB0F)
                    {
                        isNeedResponse = true;
                    }
                }
                else
                {
                    isNeedResponse = true;
                }
                if (null != _server && isNeedResponse)
                {
                    if (x300.CommandID == 0xCC00)
                    {
                        byte[] cc00 = Get0xCC00(x300);
                        var    ret  = 0;
                        if (data.PackageType == AsyncDataPackageType.TCP)
                        {
                            ret = _server.Send(data.SocketHandle, cc00);
                        }
                        else
                        {
                            ret = _server.Send(Port, IP, cc00);
                        }
                        if (1 != ret)
                        {
                            ShowUnhandledMessage(format("{0}Cannot send data to ip:{1}({2}): {3} [{4}]",
                                                        Now, IP, Port, CustomConvert.GetHex(cc00), data.PackageType));
                        }
                        cc00 = null;
                    }
                    else if (x300.CommandID == 0xBB0F)
                    {
                        byte smsType = byte.Parse(ConfigurationManager.AppSettings["SMS_SUBMIT_TYPE"]);
                        // 0xBB0F命令需要服务器发送时
                        // 2600200A0FBB1001000000000000000101383938363030363631353039313130303136343302
                        if (smsType == SMSUtility.SUBMIT_BY_DB)
                        {
                            string sender = x300.TerminalID;
                            // 170020140FBB10FFFF0139535986930101089001495000
                            string cmd = "170020" + CustomConvert.GetHex(x300.TerminalType) + "0FBB10FFFF0" + sender + "01010" + sender;
                            using (var bll = new TerminalBLL())
                            {
                                var terminal = bll.Find(f => f.Sim.Equals(sender));
                                using (var cbll = new CommandBLL())
                                {
                                    var obj = cbll.GetObject();
                                    obj.DestinationNo = sender;
                                    obj.Status        = (byte)CommandStatus.Waiting;
                                    obj.Content       = cmd;
                                    obj.Terminal      = null == terminal ? (int?)null : terminal.id;
                                    obj.SendUser      = null;
                                    obj = cbll.Add(obj);
                                }
                            }
                        }
                    }
                    else
                    {
                        // 返回回执
                        TX300Resp resp = new TX300Resp();
                        resp.CommandID  = x300.CommandID;
                        resp.PackageID  = x300.PackageID;
                        resp.SequenceID = x300.SequenceID;
                        resp.Status     = 0;
                        resp.Package();
                        var ret = 0;
                        if (data.PackageType == AsyncDataPackageType.TCP)
                        {
                            ret = _server.Send(data.SocketHandle, resp.Content);
                        }
                        else
                        {
                            ret = _server.Send(Port, IP, resp.Content);
                        }
                        if (1 != ret)
                        {
                            ShowUnhandledMessage(format("{0}Cannot send data to {1}:{2}: {3} [{4}]", Now, IP, Port, CustomConvert.GetHex(resp.Content), data.PackageType));
                        }
                    }
                }
                index += x300.TotalLength;
                x300   = null;
            }
        }