63 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			63 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using log4net;
							 | 
						|||
| 
								 | 
							
								using Mina.Core.Buffer;
							 | 
						|||
| 
								 | 
							
								using Mina.Core.Session;
							 | 
						|||
| 
								 | 
							
								using Mina.Filter.Codec;
							 | 
						|||
| 
								 | 
							
								using Mina.Filter.Codec.Demux;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.Port
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    internal class MyMinaDecoder : IMessageDecoder
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        private readonly ILog logger = LogManager.GetLogger(typeof(SocketHelper));
							 | 
						|||
| 
								 | 
							
								        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            logger.Info("Decodable");
							 | 
						|||
| 
								 | 
							
								            return MessageDecoderResult.OK;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            DecodeReturn decodeReturn= new DecodeReturn();
							 | 
						|||
| 
								 | 
							
								            logger.Info("Decode");
							 | 
						|||
| 
								 | 
							
								            int length = input.Remaining;
							 | 
						|||
| 
								 | 
							
								            byte functionCode = input.Get(7);
							 | 
						|||
| 
								 | 
							
								            if (functionCode == 4)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                int a = input.Get(length - 2);
							 | 
						|||
| 
								 | 
							
								                int b = input.Get(length - 1);
							 | 
						|||
| 
								 | 
							
								                int c = input.Get(length - 3);
							 | 
						|||
| 
								 | 
							
								                int d = input.Get(length - 4);
							 | 
						|||
| 
								 | 
							
								                //Console.WriteLine("a");
							 | 
						|||
| 
								 | 
							
								                //Console.WriteLine(a);
							 | 
						|||
| 
								 | 
							
								                //Console.WriteLine("b");
							 | 
						|||
| 
								 | 
							
								                //Console.WriteLine(b);
							 | 
						|||
| 
								 | 
							
								                //var r = Convert.ToString((a >> 14) | (b << 2), 2).PadLeft(18, '0').ToCharArray();
							 | 
						|||
| 
								 | 
							
								                //bool f = r.Any(c => c == '1');
							 | 
						|||
| 
								 | 
							
								                logger.Info($"查状态收到返回a:{a};b:{b};c:{c};d:{d}");
							 | 
						|||
| 
								 | 
							
								                bool f = false;
							 | 
						|||
| 
								 | 
							
								                if(a>0|| b>0||c>0||d>0)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    f= true;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                output.Write(f);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            input.Position = length;
							 | 
						|||
| 
								 | 
							
								            return MessageDecoderResult.OK;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void FinishDecode(IoSession session, IProtocolDecoderOutput output)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								    public class DecodeReturn
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public int CodeFunction;
							 | 
						|||
| 
								 | 
							
								        public bool Flag;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |