Beispiel #1
0
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            BinaryRequestInfo request = (BinaryRequestInfo)commandContext.RequestInfo;

            byte[] sim    = new byte[6];
            byte[] header = headerToByteArray(request.Key);
            byte[] body   = request.Body;
            Buffer.BlockCopy(body, 0, sim, 0, 6);
            if (!Utility.CodeUtils.CRC16_validate(header, body))
            {
                commandContext.Cancel = true;
            }

            //sim卡号
            string code = BitConverter.ToString(sim, 0, sim.Length).Replace("-", "").Substring(1);

            //打印燃气设备号
            commandContext.Session.Logger.Info("燃气智能检测终端编号:" + code);

            object obj = new BLL.Device().getDeviceIdByCode(code);

            if (null == obj || string.IsNullOrEmpty(obj.ToString()))
            {
                commandContext.Cancel = true;
            }
            else
            {
                RQSession session = (RQSession)commandContext.Session;
                session.ID = Convert.ToInt32(obj);
            }
        }
Beispiel #2
0
        public NodeData insertNode(MyAppSession session, BinaryRequestInfo package)
        {
            string id   = package.Key;
            string ip   = session.SocketSession.RemoteEndPoint.Address.ToString();
            string port = session.SocketSession.RemoteEndPoint.Port.ToString();

            //Console.WriteLine(id);
            if (!_allNode.ContainsKey(ip))
            {
                NodeData nd = new NodeData();
                nd.ID   = id;
                nd.IP   = ip;
                nd.PORT = port;
                _allNode.Add(ip, nd);
            }
            SensorData sd = new SensorData();

            sd.parsePackage(package, _allNode[ip]);
            for (int i = 0; i < 42; i++)
            {
                //if(i < 40)
                //{
                //     //_allNode[ip].Data[i].Add(sd.Data[i]);
                //     if(_allNode[ip].Data[i].Count == 0)
                //         _allNode[ip].Data[i].Add(sd.Data[i]);
                //     else
                //         _allNode[ip].Data[i][0] = sd.Data[i];
                // }


                //_allNode[ip].Data[i].Add(sd.Data[i]);
                if (_allNode[ip].Data[i].Count == 0)
                {
                    _allNode[ip].Data[i].Add(sd.Data[i]);
                }
                else
                {
                    if (i < 40)
                    {
                        _allNode[ip].Data[i][0] = sd.Data[i];
                    }
                    else
                    {
                        _allNode[ip].Data[i][0] = sd.Data[(i - 40) * 350 + 40];
                    }
                }


                // else
                //{
                //    for (int j = 0; j < 250; j++)
                //    {
                //        _allNode[ip].Data[i].Add(sd.Data[((i-40)*250+40+j)]);
                //    }

                //}
            }
            return(_allNode[ip]);
        }
Beispiel #3
0
        public override void ExecuteCommand(MsgPackSession session, BinaryRequestInfo requestInfo)
        {
            var serializer = SerializationContext.Default.GetSerializer <TMsgPack>();

            using (var stream = new MemoryStream(requestInfo.Body))
            {
                var unpackedObject = serializer.Unpack(stream) as TMsgPack;
                ExecuteCommand(session, unpackedObject);
            }
        }
        /// <summary>
        /// 数据接收
        /// </summary>
        public void OnRequestReceived(ClientSession session, BinaryRequestInfo requestInfo) {
            ByteBuffer buffer = new ByteBuffer(requestInfo.Body);
            int commandId = buffer.ReadShort();
            Protocal c = (Protocal)commandId;
            string className = "Junfine.Dota.Message." + c;
            Console.WriteLine("OnRequestReceived--->>>" + className);

            Type t = Type.GetType(className);
            IMessage obj = (IMessage)Activator.CreateInstance(t);
            if (obj != null) obj.OnMessage(session, buffer);
            obj = null; t = null;   //释放内存
        }
Beispiel #5
0
        /// <summary>
        /// 数据接收
        /// </summary>
        public void OnRequestReceived(ClientSession session, BinaryRequestInfo requestInfo)
        {
            ByteBuffer buffer    = new ByteBuffer(requestInfo.Body);
            int        commandId = buffer.ReadShort();
            Protocal   c         = (Protocal)commandId;
            string     className = "SimpleFramework.Message." + c;

            Console.WriteLine("OnRequestReceived--->>>" + className);

            Type     t   = Type.GetType(className);
            IMessage obj = (IMessage)Activator.CreateInstance(t);

            if (obj != null)
            {
                obj.OnMessage(session, buffer);
            }
            obj = null; t = null;   //释放内存
        }
Beispiel #6
0
        public static void ProcessMsg(BinaryAppSession session, BinaryRequestInfo requestInfo)
        {
            //LogHelper.Log.Info(" 接收到客户端消息内容:" + requestInfo.Key+" len:"+requestInfo.Body);
            //session.Send(requestInfo.Body);
            //LogHelper.Log.Info(" 发送给客户端的消息:" + requestInfo.Body);

            //StringBuilder sb = new StringBuilder();
            //Array.ForEach(requestInfo.Body, b => sb.Append($"{b} "));

            LogHelper.Log.Info($" ASCII码转换:{Encoding.ASCII.GetString(requestInfo.Body)}");
            byte[] msg      = requestInfo.Body;
            string clientID = Encoding.ASCII.GetString(msg, 0, 16);

            string[] revMsg = BitConverter.ToString(msg).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            switch (clientID)
            {
            case "ECH":
                LogHelper.Log.Info("ECH Revice:" + BitConverter.ToString(msg));
                break;
            }
        }
Beispiel #7
0
        internal void parsePackage(BinaryRequestInfo package, NodeData nodeData)
        {
            ushort temp = 0;

            //for (int i = 0; i < 21; i++)
            for (int i = 0; i < 519; i++)
            {
                temp  = (ushort)(package.Body[(2 * i) + 1]);
                temp |= (ushort)((package.Body[(2 * i) + 0] << 8) & 0xff00);
                if (i < 8)
                {
                    data[i] = temp * 1.0 / 50000 * 5 / 120.0 / 2.0 * 1000;
                }
                else if (i < 16)
                {
                    data[i] = temp * 1.0 / 50000 * 5 / 120.0 / 2.0 * 1000;
                }
                else if (i < 19)
                {
                    ushort index = 0x01;
                    for (int m = 0; m < 8; m++)
                    {
                        data[(i - 16) * 8 + 16 + m] = ((temp & index) == 0 ? 0 : 1);
                        index <<= 1;
                    }
                }
                else if (i >= 19)
                {
                    //data[i + 21] = temp * 1.0 / 4096 * 3.3 / 120.0 * 1000;
                    if (temp != 0x00)
                    {
                        data[i + 21] = ((temp * 1.0 / 4096.0 * 3.3 * 5.0 / 3.0)) / 0.025 - 92f;
                    }
                }
            }
        }
Beispiel #8
0
        public void OnRequesting(MsgPackSession session, BinaryRequestInfo requestInfo)
        {
            Client client = Session2ClientTable[session];
            MyData data   = null;

            try
            {
                data = PacketTranslator.Unpack(requestInfo.Body);
            }
            catch (Exception e)
            {
                Debug(string.Format("error at parse client request {0} {1}", e.Message, e.TargetSite));
                Debug(string.Format("error messsage {0} {1}", requestInfo?.ToString(), requestInfo.Body?.ToString()));
                session.Close();
                return;
            }
            TransferType request = PacketTranslator.GetTransferType(requestInfo.Key);

            //OutPut(string.Format("请求协议为{0}, 内容为{1}", data.Protocol.ToString(), data.Body[0]));
            if (client.UserName == null && !request.Equals(TransferType.TypeLogin))
            {
                OutPut(string.Format("{0} 未登录客户端,关闭连接", client.IP));
                session.Close();
                return;
            }

            if (data.Description == PacketDescription.Client2Hall)
            {
                switch (request)
                {
                case TransferType.TypeLogin:                              //登录相关
                    switch (data.Protocol)
                    {
                    case protocol.Login:
                        client.CheckUserName(data);
                        break;

                    case protocol.Register:                               //用户注册
                        client.Register(data);
                        break;

                    case protocol.PasswordChange:                         //密码修改
                        break;

                    default:
                        return;
                    }
                    break;

                case TransferType.TypeMessage:                            //公共事件 比如 聊天
                    MessageForward(client, data);
                    break;

                case TransferType.TypeSwitch:                               //切换room和hall
                    RoomSwitch(client, data);
                    break;

                case TransferType.TypeUserProfile:                          //修改个人信息
                    client.UpDateProfile(data);
                    break;

                default:
                    Debug(string.Format("{0} 对聊天大厅无效的请求", client.UserName));
                    break;;
                }
            }
            else if (data.Description == PacketDescription.Client2Room)
            {
                switch (request)
                {
                case TransferType.TypeMessage:                            //公共事件 比如 聊天
                    MessageForward(client, data);
                    break;

                case TransferType.TypeGameControll:                       //游戏内各操作
                    client.ControlGame(data);
                    break;

                case TransferType.TypeSwitch:                               //切换room和hall
                    RoomSwitch(client, data);
                    break;

                default:
                    Debug(string.Format("{0} 对ROOM无效的请求", client.UserName));
                    break;;
                }
            }
            else
            {
                OutPut("无效的客户端请求");
            }
        }
Beispiel #9
0
 /// <summary>
 ///客户端请求处理
 /// </summary>
 /// <param name="session">会话</param>
 /// <param name="requestInfo">请求信息</param>
 void Server_NewRequestReceived(MsgPackSession session, BinaryRequestInfo requestInfo)
 {
     hall.OnRequesting(session, requestInfo);
 }
 private void AppServer_NewRequestReceived(BnrySession session, BinaryRequestInfo requestInfo)
 {
 }
Beispiel #11
0
        /// <summary>
        /// 新请求处理函数     主要的数据处理做在这里
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        private void appServer_NewRequestReceived(MyAppSession session, BinaryRequestInfo requestInfo)
        {
            //session.Send("OK");
            try
            {
                if (true)
                {
                    MAC = Convert.ToString(requestInfo.Key[4], 16);                         //获取当前接收到的节点的MAC地址
                    int i = 0;
                    if (MAC.Equals("e618"))                                                 //不同节点精度不同  针对相应节点的数据精度优化
                    {
                        for (i = 0; i < 700 / 2; i++)
                        {
                            int temp1 = 0;
                            int temp2 = 0;
                            temp1 = requestInfo.Body[2 * i + 0];
                            temp2 = requestInfo.Body[2 * i + 1];
                            int temp = 0;
                            temp          = (ushort)(temp2);
                            temp         |= (ushort)((temp1 << 8) & 0xff00);
                            trans_data[i] = (temp * 1.0 / 65535.0 * 4.096 - 2.562f) * 37.69f;
                        }

                        for (i = 350; i < 1400 / 2; i++)
                        {
                            int temp1 = 0;
                            int temp2 = 0;
                            temp1 = requestInfo.Body[2 * i + 0];
                            temp2 = requestInfo.Body[2 * i + 1];
                            int temp = 0;
                            temp          = (ushort)(temp2);
                            temp         |= (ushort)((temp1 << 8) & 0xff00);
                            trans_data[i] = (temp * 1.0 / 65535.0 * 4.096 - 2.519f) * 39.54f;
                        }
                    }
                    else if (MAC.Equals("f2c7"))                                            //不同节点精度不同  针对相应节点的数据精度优化
                    {
                        for (i = 0; i < 700 / 2; i++)
                        {
                            int temp1 = 0;
                            int temp2 = 0;
                            temp1 = requestInfo.Body[2 * i + 0];
                            temp2 = requestInfo.Body[2 * i + 1];
                            int temp = 0;
                            temp          = (ushort)(temp2);
                            temp         |= (ushort)((temp1 << 8) & 0xff00);
                            trans_data[i] = (temp * 1.0 / 65535.0 * 4.096 - 2.566f) * 38.66f;
                        }
                        for (i = 350; i < 1400 / 2; i++)
                        {
                            int temp1 = 0;
                            int temp2 = 0;
                            temp1 = requestInfo.Body[2 * i + 0];
                            temp2 = requestInfo.Body[2 * i + 1];
                            int temp = 0;
                            temp          = (ushort)(temp2);
                            temp         |= (ushort)((temp1 << 8) & 0xff00);
                            trans_data[i] = (temp * 1.0 / 65535.0 * 4.096 - 2.542f) * 38.12f;
                        }
                    }
                    data1_show_b4 = (trans_data[100] + trans_data[103] + trans_data[105] + trans_data[107] + trans_data[109]) / 5.0f;       //采用平均值的形式取一组数据
                    data2_show_b4 = (trans_data[500] + trans_data[503] + trans_data[505] + trans_data[507] + trans_data[509]) / 5.0f;
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
            }
            finally
            {
                DateTime Time = DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond);
                current_ds.rtime   = Time;
                current_ds.hor     = data1_show_b4;
                current_ds.ver     = data2_show_b4;
                current_ds.macaddr = MAC.ToString();
                que.Enqueue(current_ds);                 //向队列中加入最新的数据  由于存储速度的限制  显示功能不能用这个队列
                package_cnt++;
            }
        }
Beispiel #12
0
        void OnReceiveHandler(BinaryRequestInfo package)
        {
            var e = new WebSocket4Net.DataReceivedEventArgs(package.Data);

            OnDataReceived(e);
        }
Beispiel #13
0
 private static void ServerOnNewRequestReceived(TcpSession session, BinaryRequestInfo requestInfo)
 {
     Console.WriteLine($"Current connected clients number:{_server.GetAllSessions().Count()},accept message from client:{session.SessionID}, the message is:{Encoding.UTF8.GetString(requestInfo.Body)}");
 }
Beispiel #14
0
 static void FixedHeaderAppServer_NewRequestReceived(FixedHeaderSession session, BinaryRequestInfo requestInfo)
 {
     session.Send(requestInfo.Key, requestInfo.Body);
 }