Ejemplo n.º 1
0
        public static byte[] SendCommand_68_serialtest(byte[] data, byte dataLength, string nodeMac, int frameNum, bool numflag)
        {
            SerialPortFrame frame = new SerialPortFrame(data, dataLength);

            frame.NodeMac = nodeMac;

            frame.FrameCount = (ushort)frameNum;

            //固定帧序号
            if (numflag)
            {
                frame.FrameCount = (ushort)6;
            }
            byte[] serialPortFrame = frame.Send();//形成串口通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(serialPortFrame, Convert.ToByte(serialPortFrame.Length));

            netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            netFrame.FrameCount        = (ushort)frameNum;
            //固定帧序号
            if (numflag)
            {
                netFrame.FrameCount = (ushort)6;
            }
            return(netFrame.Send());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// RSSI读取,68帧内加入了帧序号,用于区分重复帧
        /// </summary>
        /// <param name="frameNum">帧序号</param>
        /// <param name="destinationMac">最终目的设备的MAC</param>
        /// <param name="length">命令总长度</param>
        /// <param name="commandID">命令标识</param>
        /// <param name="commandPayload">命令负载</param>
        /// <returns></returns>
        public static byte[] SendCommand_68_ToNode(int frameNum, string destinationMac, byte length, byte[] commandID, byte[] commandPayload)
        {
            #region 构建68帧
            SerialPortFrame frame = new SerialPortFrame(commandID, commandPayload, length);
            frame.ConcentratorMac = ConcentratorMac;

            //AnalysisProcess.Node_frame = frameNum;
            //frame.FrameCount = (ushort)AnalysisProcess.Node_frame;

            frame.FrameCount = (ushort)frameNum;

            if (destinationMac == ConcentratorMac)//目标是集中器
            {
                frame.NodeMac          = "0000";
                frame.CommunicationWay = SerialPortFrame.Communication.InnerNet;
            }
            else//目标是节点
            {
                frame.NodeMac          = destinationMac;
                frame.CommunicationWay = SerialPortFrame.Communication.Nontransparent;
            }
            //frame.NeedAnswer = true;
            byte[] serialPortFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(serialPortFrame, Convert.ToByte(serialPortFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }
Ejemplo n.º 3
0
        //网关更新,用于发送中间的数据帧
        public static byte[] SendCommand_68_SendGatewayData(bool needACK, int frame_position, byte[] dataPayload, byte length, ushort Framecount)
        {
            #region 构建串口帧
            SerialPortFrame frame = new SerialPortFrame(dataPayload, Convert.ToByte(dataPayload.Length));
            if (frame_position == 0)
            {
                frame.TransferState = SerialPortFrame.FrameState.FirstFrame;
            }
            else if (frame_position == 1)
            {
                frame.TransferState = SerialPortFrame.FrameState.MidFrame;
            }
            else if (frame_position == 2)
            {
                frame.TransferState = SerialPortFrame.FrameState.LastFrame;
            }
            frame.NeedAnswer       = needACK;
            frameNum               = Framecount;
            frame.FrameCount       = Framecount;
            frame.CommunicationWay = SerialPortFrame.Communication.InnerNet;
            byte[] intranetFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(intranetFrame, Convert.ToByte(intranetFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 速率测试中,用于发送数据帧
        /// </summary>
        /// <param name="destinationMac"></param>
        /// <param name="needACK"></param>
        /// <param name="mode"></param>
        /// <param name="state"></param>
        /// <param name="count"></param>
        /// <param name="dataPayload"></param>
        /// <returns></returns>
        public static byte[] SendCommand_68_SeriData(string destinationMac, bool needACK, SerialPortFrame.Communication mode, SerialPortFrame.FrameState state, ushort count, byte[] dataPayload)
        {
            #region 构建串口帧
            SerialPortFrame frame = new SerialPortFrame(dataPayload, Convert.ToByte(dataPayload.Length));
            frame.ConcentratorMac = ConcentratorMac;

            if (destinationMac == ConcentratorMac)//目标是集中器
            {
                frame.NodeMac          = "0000";
                frame.CommunicationWay = SerialPortFrame.Communication.InnerNet;
            }
            else//目标是节点
            {
                frame.NodeMac          = destinationMac;
                frame.CommunicationWay = mode;
            }
            frame.TransferState = state;
            frame.NeedAnswer    = needACK;
            frame.FrameCount    = count;
            byte[] serialPortFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(serialPortFrame, Convert.ToByte(serialPortFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 发送最终目的地是节点的命令帧.
        /// </summary>
        /// <param name="destinationMac">最终目的设备的MAC.</param>
        /// <param name="length">命令总长度.</param>
        /// <param name="commandID">命令标识.</param>
        /// <param name="commandPayload">命令负载.</param>
        /// <returns></returns>
        public static byte[] SendCommand_68_ToNode(string destinationMac, byte length, byte[] commandID, byte[] commandPayload)
        {
            #region 构建68帧
            SerialPortFrame frame = new SerialPortFrame(commandID, commandPayload, length);
            frame.ConcentratorMac = ConcentratorMac;

            if (destinationMac.Length > 4)
            {
                frame.NodeMac = destinationMac.Substring(destinationMac.Length - 4, 4);
            }
            else
            {
                frame.NodeMac = destinationMac;
            }
            frame.CommunicationWay = SerialPortFrame.Communication.Nontransparent;

            byte[] serialPortFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(serialPortFrame, Convert.ToByte(serialPortFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }
Ejemplo n.º 6
0
        //重载
        public static byte[] SendCommand_68(string destinationMac, byte length, byte[] commandID, string commandPayload, byte commandcount)
        {
            #region 构建68帧
            byte[] commandLoad = Character.StringToBytes(commandPayload);
            byte[] command     = new byte[4];
            command[0] = commandLoad[1];
            command[1] = commandLoad[0];
            command[2] = 0x0A;
            command[3] = 0xFD;

            SerialPortFrame frame = new SerialPortFrame(commandID, command, length);
            if (ConcentratorMac.Length < 4)
            {
                ConcentratorMac = "00" + ConcentratorMac;
            }
            if (destinationMac.Length < 4)
            {
                destinationMac = "00" + destinationMac;
            }
            if (ConcentratorMac.Length > 4)
            {
                ConcentratorMac = ConcentratorMac.Substring(ConcentratorMac.Length - 4, 4);
            }
            if (destinationMac.Length > 4)
            {
                destinationMac = destinationMac.Substring(destinationMac.Length - 4, 4);
            }
            frame.ConcentratorMac = ConcentratorMac;
            if (destinationMac == ConcentratorMac)//目标是集中器
            {
                frame.NodeMac          = "0000";
                frame.CommunicationWay = SerialPortFrame.Communication.InnerNet;
            }
            else//目标是节点
            {
                if (destinationMac.Length > 4)
                {
                    frame.NodeMac = destinationMac.Substring(4, 4);
                }
                else
                {
                    frame.NodeMac = destinationMac;
                }
                frame.CommunicationWay = SerialPortFrame.Communication.Nontransparent;
            }
            frame.FrameCount = commandcount;
            byte[] serialPortFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(serialPortFrame, Convert.ToByte(serialPortFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 发送最终目的地是集中器的67组播数据帧.(全网通信)
        /// </summary>
        /// <param name="ipNumber">节点数量</param>
        /// <param name="ipLoad">包含节点数组</param>
        /// <param name="destinationMac">最终目的设备的MAC</param>
        /// <param name="length">数据总长度</param>
        /// <param name="dataPayload">数据负载</param>
        /// <returns></returns>
        public static byte[] SendCommand_67_data(byte ipNumber, string[] ipLoad, string destinationMac, bool needACK, byte length, byte[] dataPayload)
        {
            #region 构建67帧
            NodeMulticastFrame frame67            = new NodeMulticastFrame(ipLoad, ipNumber);
            byte[]             NodeMulticastFrame = frame67.Send();//形成节点组播帧
            #endregion

            #region 构建68帧
            SerialPortFrame frame = new SerialPortFrame(dataPayload, Convert.ToByte(dataPayload.Length));
            if (ConcentratorMac.Length < 4)
            {
                ConcentratorMac = "00" + ConcentratorMac;
            }
            if (destinationMac.Length < 4)
            {
                destinationMac = "00" + destinationMac;
            }

            if (ConcentratorMac.Length > 4)
            {
                ConcentratorMac = ConcentratorMac.Substring(ConcentratorMac.Length - 4, 4);
            }
            if (destinationMac.Length > 4)
            {
                destinationMac = destinationMac.Substring(destinationMac.Length - 4, 4);
            }
            frame.NeedAnswer       = needACK;
            frame.ConcentratorMac  = ConcentratorMac;
            frame.NodeMac          = "eeee";
            frame.CommunicationWay = SerialPortFrame.Communication.phone;

            byte[] serialPortFrame = frame.Send();//形成串口通信帧
            #endregion

            #region 构建组合帧
            byte[] MulFrame = new byte[NodeMulticastFrame.Length + serialPortFrame.Length];
            NodeMulticastFrame.CopyTo(MulFrame, 0);
            serialPortFrame.CopyTo(MulFrame, NodeMulticastFrame.Length);
            #endregion

            #region 构建网络通信帧

            /* 构建网络通信帧 */
            NetCommunicationFrame netFrame = new NetCommunicationFrame(MulFrame, Convert.ToByte(MulFrame.Length));
            netFrame.Encryption  = false;
            netFrame.NeedAnswer  = false;
            netFrame.FrameFormat = NetCommunicationFrame.FrameType.DataFrame;
            receiveByte();
            netFrame.MobilePhoneMAC        = PhoneMAC;
            netFrame.GatewayClassification = GatewayType;
            netFrame.GatewayMAC            = GatewayMAC;
            netFrame.FrameCount            = 0;

            netFrame.TransferDirection = NetCommunicationFrame.Direction.Multicast;
            if (packetFrameType == FrameType.OutterNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.MobilePhone2Server2Gateway;
                netFrame.ServerIP          = SeverIp;
            }
            if (packetFrameType == FrameType.InnerNet)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Mobile2Gateway;
            }
            if (packetFrameType == FrameType.Serial)
            {
                netFrame.TransferDirection = NetCommunicationFrame.Direction.Computer2Gateway;
            }

            return(netFrame.Send());

            #endregion
        }