Ejemplo n.º 1
0
        public static void SendMessage(Socket udp, byte id, params byte[] payload)
        {
            byte[] msg = new byte[payload.Length + 4];

            uint innerLen = (uint)payload.Length;

            // bridge message format (all numbers big endian)
            //  bridge command - UINT8 (0 = transmit)
            // --start payload--
            //  inner command - UINT8
            //  inner payload length - UINT16
            //  payload
            msg[0] = BRIDGE_CMD_TX;
            msg[1] = id;
            msg[2] = (byte)((innerLen >> 8) & 0xff);
            msg[3] = (byte)(innerLen & 0xff);

            // copy over the payload
            Buffer.BlockCopy(payload, 0, msg, 4, payload.Length);

            // send that ish out
            udp.SendTo(msg, ControllerEP);
            if (payload.Length == 8)
            {
                msg = new byte[payload.Length + 9];

                BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg);
                // write a slot for the timestamp (zero as we don't have any timestamp)
                writer.WriteUInt16(0);
                writer.WriteInt32(0);

                // write message type
                writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED);

                // write the length as bullstuff
                writer.WriteInt16(0);

                // only send for all message
                // change the message ID, only send a subset of the stuffs
                writer.WriteBytes(payload);

                // set the stuff stuff
                udp.SendTo(msg, MulticastEP);
            }
        }
        public static void SendMessage(Socket udp, byte id, params byte[] payload)
        {
            byte[] msg = new byte[payload.Length + 4];

            uint innerLen = (uint)payload.Length;

            // bridge message format (all numbers big endian)
            //  bridge command - UINT8 (0 = transmit)
            // --start payload--
            //  inner command - UINT8
            //  inner payload length - UINT16
            //  payload
            msg[0] = BRIDGE_CMD_TX;
            msg[1] = id;
            msg[2] = (byte)((innerLen >> 8) & 0xff);
            msg[3] = (byte)(innerLen & 0xff);

            // copy over the payload
            Buffer.BlockCopy(payload, 0, msg, 4, payload.Length);

            // send that ish out
            udp.SendTo(msg, ControllerEP);
            if (payload.Length == 8) {
                msg = new byte[payload.Length + 9];

                BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg);
                // write a slot for the timestamp (zero as we don't have any timestamp)
                writer.WriteUInt16(0);
                writer.WriteInt32(0);

                // write message type
                writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED);

                // write the length as bullstuff
                writer.WriteInt16(0);

                // only send for all message
                // change the message ID, only send a subset of the stuffs
                writer.WriteBytes(payload);

                // set the stuff stuff
                udp.SendTo(msg, MulticastEP);
            }
        }