コード例 #1
0
        protected bool?SendParam(CommandTuple cmdTuple, CommandParam cmdParam, bool ack = true)
        {
            // ReSharper disable once InconsistentNaming
            string ACK = ack ? "SEND_WITH_ACK" : "SEND_NO_ACK";
            // ReSharper disable once InconsistentNaming
            string DataACK = ack ? "DATA_WITH_ACK" : "DATA_NO_ACK";
            // ReSharper disable once StringLiteralTypo
            string fmt = "<BBBIBBH" + cmdParam.Format();

            SequenceCounter[ACK] = (SequenceCounter[ACK] + 1) % 256;

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName[DataACK]);
            cmd.InsertData((byte)BufferIds[ACK]);
            cmd.InsertData((byte)SequenceCounter[ACK]);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));

            cmd.InsertTuple(cmdTuple);
            cmd.InsertParam(cmdParam);

            if (ack)
            {
                return(SendCommandAck(cmd.Export(fmt), SequenceCounter["SEND_WITH_ACK"]));
            }

            SendCommandNoAck(cmd.Export(fmt));
            return(null);
        }
コード例 #2
0
        protected bool SendNoParam(CommandTuple cmdTuple)
        {
            SequenceCounter["SEND_WITH_ACK"] = (SequenceCounter["SEND_WITH_ACK"] + 1) % 256;
            // ReSharper disable once StringLiteralTypo
            const string fmt = "<BBBIBBH";

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName["DATA_WITH_ACK"]);
            cmd.InsertData((byte)BufferIds["SEND_WITH_ACK"]);
            cmd.InsertData((byte)SequenceCounter["SEND_WITH_ACK"]);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));
            cmd.InsertTuple(cmdTuple);

            return(SendCommandAck(cmd.Export(fmt), SequenceCounter["SEND_WITH_ACK"]));
        }
コード例 #3
0
        // ReSharper disable once IdentifierTypo
        protected bool SendSinglePcmd(CommandTuple cmdTuple, CommandParam cmdParam)
        {
            SequenceCounter["SEND_NO_ACK"] = (SequenceCounter["SEND_NO_ACK"] + 1) % 256;
            // ReSharper disable once StringLiteralTypo
            string fmt = "<BBBIBBH" + cmdParam.Format();

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName["DATA_NO_ACK"]);
            cmd.InsertData((byte)BufferIds["SEND_NO_ACK"]);
            cmd.InsertData((byte)SequenceCounter["SEND_NO_ACK"]);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));

            cmd.InsertTuple(cmdTuple);
            cmd.InsertParam(cmdParam);

            return(SafeSend(cmd.Export(fmt)));
        }
コード例 #4
0
        protected void AckPacket(int bufferId, int packetId)
        {
            // ReSharper disable once StringLiteralTypo
            const string fmt         = "<BBBIB";
            int          newBufferId = (bufferId + 128) % 256;

            Command cmd = new Command {
                SequenceId = newBufferId
            };

            cmd.InsertData((byte)DataTypesByName["ACK"]);
            cmd.InsertData((byte)newBufferId);
            cmd.InsertData((byte)cmd.SequenceId);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));
            cmd.InsertData((byte)packetId);

            SafeSend(cmd.Export(fmt));
        }
コード例 #5
0
        protected void SendPong(byte[] data)
        {
            int byteSize = 4, totalByteSize = byteSize + data.Length;
            // ReSharper disable once StringLiteralTypo
            const string fmt = "<BBBI";

            SequenceCounter["PONG"] = (SequenceCounter["PONG"] + 1) % 256;

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName["DATA_NO_ACK"]);
            cmd.InsertData((byte)BufferIds["PONG"]);
            cmd.InsertData((byte)SequenceCounter["PONG"]);
            cmd.InsertData((uint)(StructConverter.PacketSize(fmt) + data.Length));

            byte[] initCommand = cmd.Export(fmt);
            Array.Resize(ref initCommand, totalByteSize);

            data.CopyTo(initCommand, byteSize);

            SafeSend(initCommand);
        }